﻿using System;
using System.Data.Linq;
using DR.DBDomainModel;
using DR.Repository.Abstract;
using System.Linq;

namespace DR.Repository.Concrete.LinqToSql
{
    public class LinqToSqlDeveloperProjectRepository : LinqToSqlBaseRepository<DeveloperProject, int>, IDeveloperProjectRepository
    {
        public LinqToSqlDeveloperProjectRepository(string connectionString) : base(connectionString)
        {            
        }

        protected override Table<DeveloperProject> GetDataTable(DataContext dataContext)
        {
            return dataContext.GetTable<DeveloperProject>();
        }

        protected override System.Linq.Expressions.Expression<Func<DeveloperProject, bool>> GetIDQuery(int id)
        {
            return r => r.DeveloperProjectID == id;
        }

        protected override int GetEntityID(DeveloperProject entity)
        {
            return entity.DeveloperProjectID;
        }

        public DeveloperProject GetDeveloperProject(int developerID, int projectID)
        {
            using (DataContext dc = CreateDataContext())
            {
                var entity = dc.GetTable<DeveloperProject>().SingleOrDefault(r =>
                    (r.DeveloperID == developerID
                    && r.ProjectID == projectID));
                return entity;
            }
        }
    }
}
